

import java.io.IOException;
import java.util.List;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entities.Declares;
import entities.RegisteredUser;

import sessionbeans.ProfileBeanRemote;

/**
 * Servlet implementation class UnregisteredProfileServlet
 */
public class UnregisteredProfileServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UnregisteredProfileServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		InitialContext context;
		ProfileBeanRemote profileBean;
		String user = (String) request.getParameter("user");
		RegisteredUser visitinguser;
		List<Declares> abilities;
		
		if (user != null) {
			try {
				context = new InitialContext();
				Object ref = context.lookup("ProfileBeanRemote");
				profileBean = (ProfileBeanRemote) PortableRemoteObject.narrow(ref,ProfileBeanRemote.class);
				visitinguser = profileBean.getUser(user);
				abilities = profileBean.getAbilities(user);
				request.getSession().setAttribute("visitinguser",visitinguser);
				request.getSession().setAttribute("visitinguserabilities",abilities);
			} catch (NamingException e) {
			
			}
		}
		
		response.sendRedirect("UnregisteredProfilePage.jsp");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
